﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dycox.Collections;

namespace Dycox.Workflows
{
    public class TransitionConditionCollection : ConditionCollection
    {
        public TransitionConditionCollection(Transition owner)
        {
            if (owner == null)
                throw new ArgumentNullException("owenr");

            _transition = owner;
        }

        private Transition _transition;

        public Transition Transition
        {
            get { return _transition; }
        }

        public new TransitionCondition this[int index]
        {
            get
            {
                return (TransitionCondition)base[index];
            }
            set
            {
                if (!(value is TransitionCondition))
                    throw new ArgumentException("The specified item is not a TransitionCondition.");

                base[index] = value;
            }
        }

        protected override void AttachItem(Condition item)
        {
            TransitionCondition tc = item as TransitionCondition;
            if (tc == null)
                throw new ArgumentException("The specified item is not a TransitionCondition.");

            base.AttachItem(item);

            tc.Transition = _transition;

        }

        protected override void DeattachItem(Condition item)
        {
            base.DeattachItem(item);

            ((TransitionCondition)item).Transition = null;
        }
    }

    public class EnteringConditionCollection : TransitionConditionCollection
    {
        public EnteringConditionCollection(Transition owner)
            : base(owner)
        {

        }

        private string _errorMessage;

        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; }
        }

    }

    public enum ConditionRelation
    {
        And,
        Or
    }
}
